package com.fighthouse.service;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

import com.fighthouse.entity.Contato;



public class SendEmail {
	
	public SendEmail(){
		super();
	}
	
	public Boolean send(Contato contato){
		HtmlEmail email = new HtmlEmail();
		email.setHostName("smtp.gmail.com");
		email.setAuthentication("fighthouse.fh@gmail.com", "luta2009");
		email.setSmtpPort(465);  
        email.setSSL(true);  
        email.setTLS(true);
		try{
			
		
			//Paras
			
			//email.addTo("viagem@marquise.com.br");
			//email.addTo(returnFrom(requisicao.getDirResponsavel(), 0));
			//email.addTo(returnFrom(requisicao.getDirResponsavel(), 1));
			//email.addTo(contato.getDestinatario());
			email.addTo("fighthouse.fh@gmail.com");
			
			//De
			email.setFrom(contato.getEmail(), contato.getNome());
			
			//Assunto
			email.setSubject("Contato Atraves do site");
			
			  
			// set the html message
			email.setHtmlMsg(makeMsg(contato));
	
			// set the alternative message
			//email.setTextMsg("Your email client does not support HTML messages");
	
			// send the email
			email.send();
		
		}catch(EmailException e){
			e.printStackTrace();
			
		}
		
		
		return true;
	}
	
	private String makeMsg(Contato contato){
		String msg = "<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>" +
		"<center>" +
		"<br>" +
		"<table width='700' border='0' bgcolor='#F0F0F0' style='border:#999 thin solid;'>" +
		"<tr>" +
		"<td width='20' valign='top'>&nbsp;</td>" +
		"<td width='642' id='Conteudo' style='padding-top:20px'><font color='#000000'>" +
		"<h1 align='right'>Fight House</h1>" +
		"<p align='left'><b>Nome: </b><i>" + contato.getNome() + "</i></p>" +
		"<p align='left'><b>E-mail: </b><i>" + contato.getEmail() + "</i></p>" +
		"<p align='left'><b>Bairro: </b><i>" + contato.getBairro() + "</i></p>" +
		"<p align='left'><b>CEP: </b><i>" + contato.getCep() + "</i></p>" +
		"<p align='left'><b>Cidade: </b><i>" + contato.getCidade() + "</i></p>" +
		"<p align='left'><b>Estado: </b><i>" + contato.getEstado() + "</i></p>" +
		"<p align='left'><b>Telefone: </b><i>" + contato.getTelefone() + "</i></p>" +
		"<p align='left'><b>Celular: </b><i>" + contato.getCelular() + "</i></p>" +
		"<p align='left'><b>Mensagem: </b><i>" + contato.getMensagem() + "</i></p>" +
		"</font></td>" +
		"<td width='20' id='Conteudo' style='padding-top:20px'>&nbsp;</td>" +
		"</tr>" +
		"<tr>" +
		"<td colspan='3'>&nbsp;</td>" +
		"</tr>" +
		"</table>" +
		"</center>" +
		"</body>";
		
		return msg;
	}
	
	
}
  
